<?php


if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

if ($_POST['act'] == 'indexmode') {
  if (empty($_POST['index_mod'])) {
    err('模板参数缺失！');
  }
  if (!file_exists($_POST['index_mod'])) {
    err('参数传递的模板不存在！');
  }
  if (!copy($_POST['index_mod'], 'index.php')) {
    err('首页模板设置失败！原因：根目录（index.php文件）无写权限');
  }
  @ require ('readonly/function/write_file.php');
  @ require ('writable/set/set_html.php');

  if ($_POST['parallel'] == 1) {
    //if (file_exists('addfunds.php')) {
      copy('readonly/js/parallel.js', 'writable/js/parallel.js');
    //} else {
      //err('此功能对商业用户开放！');
    //}
  } else {
    @unlink('writable/js/parallel.js');
  }

  reset_indexhtml('index.php', 'index.html');
  alert('首页模式设置成功！', 'webmaster_central.php?get=style#po1');

} elseif ($_POST['act'] == 'style') {
  if (empty($_POST['cssfile'])) {
    $_POST['cssfile'] = 'default/1';
  }
  $style_cookie_unset = $style_set_unset = '';
  if (isset($_COOKIE['myStyle']) && $_POST['cssfile'] != $_COOKIE['myStyle']) {
    $style_cookie_unset = '<script> document.cookie=\'myStyle=; path=/;\'; </script>';
  }
  if ($_POST['cssfile'] != $web['cssfile']) {
    if ($web['html'] == true) {
      $style_set_unset .= '<div style="background-color:#FF6600; color:#FFF;">你对系统风格进行了更改，因为你开启了全静态，为刷新所有静态文件风格样式，请进行<a href="?post=html_open">一键生成全静态</a>
</div>';
    }
  }
  if (!$text = @file_get_contents('writable/set/set.php')) {
    err('无法读取设置文件！稍候再试！');
  }
  $text = preg_replace('/\$web\[(\'|\")cssfile(\'|\")\][^\;]+/', '$web[\'cssfile\'] = \''.$_POST['cssfile'].'\'', $text);
  @ require ('readonly/function/write_file.php');
  write_file('writable/set/set.php', $text);

  $s_j_set = 0;
  if ($f_js = @file_get_contents('readonly/js/main.js')) {
    if (preg_match('/\/\* +jieri_style +\*\/(.+)\/\* +\/jieri_style +\*\//isU', $f_js, $m_f_js)) {
      if (preg_match('/if *\(styleDate *\!\= *\'\'\) *\{/', $m_f_js[1])) {
        $s_j_set = 1;
      }
    }
    unset($m_f_js);
    if (abs($_POST['cssfile_jieri_auto']) != $s_j_set) {
      $tmp = array();
      $tmp[0] = '
  if((nowStyle=getCookie(\'myStyle\')) && (/^(default|jieri|other)\/\d+$/.test(nowStyle))){
    $(\'my_style\').href=\'writable/css/\'+nowStyle+\'/style.css\';
  } else {
    setCookie(\'my_style\', \'\', -366);
  }
';
      $tmp[1] = '
if (styleDate != \'\') {
  document.write(\'<link href="writable/css/jieri/\'+styleDate+\'/style.css" rel="stylesheet" type="text/css">\');
} else {
'.$tmp[0].'
}
';
      $f_js = preg_replace('/\/\* +jieri_style +\*\/(.+)\/\* +\/jieri_style +\*\//isU', '/* jieri_style */'.$tmp[abs($_POST['cssfile_jieri_auto'])].'/* /jieri_style */', $f_js);
      write_file('readonly/js/main.js', $f_js);
      $id = gmdate('YmdHis', time() + (floatval($web['time_pos']) * 3600));
      write_file('writable/require/browse_reload.txt', $id);
    }
  }
  unset($f_js);

  @ require ('writable/set/set_html.php');
  reset_indexhtml('index.php', 'index.html');

  if ($style_set_unset != '') {
    err('网站风格设置成功！'.$style_cookie_unset.$style_set_unset, 'ok');
  } else {
    alert('网站风格设置成功！'.$style_cookie_unset, 'webmaster_central.php?get=style#po1');
  }


} elseif ($_POST['act'] == 'other') {
  $style_set_unset = '';
  if ($_POST['link_type'] != $web['link_type']) {
    if ($web['html'] == true) {
      $style_set_unset .= '<div style="background-color:#FF6600; color:#FFF;">你对链接模式进行了更改，因为你开启了全静态，为刷新所有静态文件链接模式，请进行<a href="?post=html_open">一键生成全静态</a>
</div>';
    }
  }
  if (!$text = @file_get_contents('writable/set/set.php')) {
    err('无法读取设置文件！稍候再试！');
  }
  $text = preg_replace('/\$web\[(\'|\")link_type(\'|\")\].+\$web\[(\'|\")d_type(\'|\")\][^\;]+;/sU', '$web[\'link_type\'] = '.($_POST['link_type'] != 1 ? 0 : 1).';
$web[\'link_type_i\'] = '.($_POST['link_type_i'] != 1 ? 0 : 1).';
$web[\'d_type\'] = '.($_POST['d_type'] != 1 ? 0 : 1).';', $text);

  @ require ('readonly/function/write_file.php');
  write_file('writable/set/set.php', $text);
  @ require ('writable/set/set_html.php');
  reset_indexhtml('index.php', 'index.html');
  if ($style_set_unset != '') {
    err('设置成功！'.$style_set_unset, 'ok');
  } else {
    alert('设置成功！', 'webmaster_central.php?get=style#po2');
  }


} else {
  err('参数错误！');
}





?>